const formatTime = date => {
  const year = date.getFullYear()
  const month = date.getMonth() + 1
  const day = date.getDate()
  const hour = date.getHours()
  const minute = date.getMinutes()
  const second = date.getSeconds()

  return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
}

let DEBUG = true;

const log = (str) => {
  if(DEBUG) {
    console.log(str)
  }
}

const formatNumber = n => {
  n = n.toString()
  return n[1] ? n : '0' + n
}

// 获取设备唯一编码
const getUniqueCode = () => {
	let uniqueCode = ""
	
	try {
		uniqueCode = uni.getStorageSync('uniqueCode')
	} catch (e) {}
	// utilLog("设备唯一标识：" + uniqueCode)
	
	if (uniqueCode === "" || uniqueCode === undefined) { //判断是否有唯一标识
		// #ifdef  APP-PLUS
		// uniqueCode = plus.device.model + plus.device.uuid
		// utilLog(plus.device)
		// utilLog(uniqueCode)

		try {
			if (uniqueCode) {
				wx.setStorageSync('uniqueCode', uniqueCode)
			}
		} catch (e) {}
		// #endif
	}
	
	return uniqueCode
}
module.exports = {
  formatTime: formatTime,
  getUniqueCode,
  log: log,
}
